﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace DataImport
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //XmlTextReader reader = new XmlTextReader("http://rss.jobsearch.monster.com/rssquery.ashx?WT.mc_n=RSS2005_jsr&q=Sales&cy=US&baseurl=jobsearch.monster.com"); // sector Sales
            //XmlTextReader reader = new XmlTextReader("http://www.computingcareers.co.uk/searchjobsrss?Jobrole=2003"); // sectorIT
            //XmlTextReader reader = new XmlTextReader("http://www.totaljobs.com/JobSearch/RSS.aspx?Keywords=&Market=1&Industry=18"); //--- Accountancy
            //XmlTextReader reader = new XmlTextReader("http://www.totaljobs.com/JobSearch/RSS.aspx?Keywords=&Market=25&Industry=33");//public sector
            //XmlTextReader reader = new XmlTextReader("http://www.totaljobs.com/JobSearch/RSS.aspx?Keywords=&Market=14&Industry=1"); //IT
            //XmlTextReader reader = new XmlTextReader("http://rss.jobsearch.monster.com/rssquery.ashx?WT.mc_n=RSS2005_jsr&fn=4&cy=US&baseurl=jobsearch.monster.com"); //Design
            //XmlTextReader reader = new XmlTextReader("http://jobs.designweek.co.uk/searchjobsrss?DesignDisciplines=203009"); //Design
            //XmlTextReader reader = new XmlTextReader("http://jobs.designweek.co.uk/searchjobsrss?DesignDisciplines=203009"); //Design
            //XmlTextReader reader = new XmlTextReader("http://jobs.designweek.co.uk/searchjobsrss?JobFunctions=2005"); //Design
            XmlTextReader reader = new XmlTextReader("http://www.jobs.ac.uk/rss/disc/0100.xml"); //Design
        
            XmlDocument rssDoc = new XmlDocument();

            // Load the XML content into a XmlDocument
            rssDoc.Load(reader);
            // Loop for the <rss> tag

            XmlNodeList xnList = rssDoc.SelectNodes("rss/channel/item");
            foreach (XmlNode xn in xnList)
            {
                int jobProviderId = RandomNumber(9, 21);
                string title = xn["title"].InnerText;
                string description = xn["description"].InnerText;
                DateTime pubDate = DateTime.Now;//Convert.ToDateTime(xn["pubDate"].InnerText);
                DateTime closingDate = pubDate.AddDays(RandomNumber(1, 31));
                ImportDataContext idc = new ImportDataContext();
                idc.up_AddJob(title, description, closingDate, "Construction", jobProviderId);
            }            
        }

        private int RandomNumber(int min, int max)
        {
            Random random = new Random();
            return random.Next(min, max);
        }
    }
}
